<?php
    foreach ($this->container as $page) {
        // check if it is active (not recursive)
        $isActive = $page->isActive(false);
        $liClass = $isActive ? ' class="active"' : '';
        if ($page->_label !== null && $page->isVisible(true)) {
        	echo '<li ' . $liClass . '>' . $this->menu()->htmlify($page) . '</li>', PHP_EOL;
        }
        // loop next level
        foreach ($page as $page) {
            // check if it is active (recursive)
            $isActive = $page->isActive(true);
            $liClass = $isActive ? ' class="active"' : '';
            if ($page->_label !== null && $page->isVisible(true)) {
                echo '<li ' . $liClass . '>' . $this->menu()->htmlify($page);
                if ($page->_pages) {
                    echo '<ul>';
                        foreach ($page as $page) {
                            // check if it is active (recursive)
                            $isActive = $page->isActive(true);
                            $liClass = $isActive ? ' class="active"' : '';
                            if ($page->_label !== null && $page->isVisible(true)) {
                                echo '<li ' . $liClass . '>' . $this->menu()->htmlify($page);
                                if ($page->_pages) {
                                    echo '<ul>';
                                    foreach ($page as $page) {
                                        // check if it is active (recursive)
                                        $isActive = $page->isActive(true);
                                        $liClass = $isActive ? ' class="active"' : '';
                                        if ($page->_label !== null && $page->isVisible(true)) {
                                            echo '<li ' . $liClass . '>' . $this->menu()->htmlify($page) . '</li>', PHP_EOL;
                                        }
                                    }
                                    echo '</ul>';
                                }
                                echo '</li>', PHP_EOL;
                            }
                        }
                    echo '</ul>';
                }
                echo '</li>', PHP_EOL;
            }

        }
    }
